<template>
	<view class="shop-list" :style="{ padding: '0rpx '+ value.padding * 2 + 'rpx' }">
		<block v-for="(item,key) in shopList" :key="key">
			<view class="shop-item" @click="toDetail(item)">
				<image class="shop-image" :src="$util.img(item.avatar)" mode="scaleToFill"></image>
				<view class="shop-info">
					<view class="shop-name-row">
						<view class="shop-name">{{item.site_name}}</view>
						<view class="shop-distance">{{ item.distance }}</view>
					</view>
					<view class="shop-locate">{{item.full_address}}{{item.address}}</view>
					<view class="shop-time">营业时间:{{item.open_date}}</view>
					<view v-if="item.keywords_map.length" class="shop-service">
						<view v-for="(value,key) in item.keywords_map" :key="key" class="service-item">{{value}}</view>
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		name: "diy-shop-list",
		props: {
			isIndex: {
				type: Boolean,
				default: () => {
					return true;
				}
			},
			value: {
				type: Object,
				default: () => {
					return {};
				}
			},
			siteId: {
				type: [Number, String],
				default: 0
			},
			name: {
				type: String,
				default () {
					return '';
				}
			}
		},
		created() {
			if (this.$props.isIndex) {
				this.getShopList();
			} else {
				// this.shopList = this.$props.shopList;
			}
		},
		data() {
			return {
				shopList: []
			};
		},
		methods: {
			getShopList() {
				var data = {
					page: 1,
					page_size: this.value.shopCount
				};

				if (uni.getStorageSync('location')) {
					data.lat = uni.getStorageSync('location').latitude;
					data.lng = uni.getStorageSync('location').longitude;
				}

				if (this.value.sources == 'category') {
					data.category_id = this.value.categoryId;
					data.category_level = 1;
				} else if (this.value.sources == 'diy') {
					data.page_size = this.value.shopCount;
					data.site_id_arr = this.value.siteIds.toString();
				}
				this.$api.sendRequest({
					url: '/api/shop/pagecomponents',
					data: data,
					success: res => {
						if (res.code == 0 && res.data) {
							let data = res.data;
							this.shopList = data.list;
						}
					}
				});
			},
			toDetail(item) {
				this.$util.redirectTo('/otherpages/shop/index/index', {
					site_id: item.site_id
				});
			},
			goodsImg(imgStr) {
				let imgs = imgStr.split(',');
				return imgs[0] ? this.$util.img(imgs[0], {
					size: 'mid'
				}) : this.$util.getDefaultImage().default_goods_img;
			},
		}
	}
</script>

<style lang="scss" scoped>
	view {
		box-sizing: border-box;
	}

	.shop-list {}

	.shop-item {
		padding: 24rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		width: 100%;
		height: 232rpx;
		background: #FFFFFF;
		border-radius: 16rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.shop-image {
			flex-shrink: 0;
			margin-right: 24rpx;
			width: 160rpx;
			height: 160rpx;
			border-radius: 8rpx;
		}

		.shop-info {
			flex-grow: 2;

			.shop-name-row {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.shop-name {
				font-size: 32rpx;
				color: #1B1B1B;
				line-height: 45rpx;
			}

			.shop-distance {
				font-size: 24rpx;
				color: #1B1B1B;
				line-height: 33rpx;
			}

			.shop-locate,
			.shop-time {
				margin-top: 8rpx;
				font-size: 24rpx;
				color: #999999;
				line-height: 33rpx;
			}

			.shop-service {
				margin-top: 12rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				.service-item {
					margin-right: 16rpx;
					padding: 4rpx;
					border-radius: 4rpx;
					font-size: 20rpx;
					color: #FC6E20;
					line-height: 28rpx;
					border: 1rpx solid #FC6E20;
				}
			}

		}
	}
</style>